<template>
  <div class="container">
     <el-card class="box-card">
        <questionsAdd @list="list" @newList="newList"></questionsAdd>
 <BasicQuestion :arr="arr" @remove="remove" :total="total" :showExamination.sync="showExamination" @setListItem="getListItem" @add="add"></BasicQuestion>
 <el-row type="flex" justify="end" align="middle" style="height: 60px">
        <el-pagination
          background
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page.sync="pageForm.page"
          :page-sizes="[ 5,10, 15, 20]"
          :page-size="pageForm.pagesize"
          layout=" prev, pager, next,sizes, jumper"
          :total="total"
        />
              </el-row>
    </el-card>
<AuditPreview :showExamination.sync="showExamination" :list="getListItemdata"></AuditPreview>
<!-- 分页组件============================================================================================================================================================ -->

  </div>
</template>

<script>

import { remove, list } from '../../api/hmmm/questions'
import { questionType, chkType, publishType, difficulty, status } from '../../api/hmmm/constants'
import BasicQuestion from '../components/BasicQuestion.vue'
import questionsAdd from '../components/questions-add.vue'
import AuditPreview from '../components/AuditPreview.vue'
export default {
  components: {
    BasicQuestion,
    questionsAdd,
    AuditPreview
  },
  data () {
    return {
      activeName: 'first',
      total: 0,
      arr: [],
      questionType,
      getListItemdata: [],
      chkType,
      publishType,
      difficulty,
      status,
      showExamination: false,
      qusetionsDetail: {},
      pageForm: {
        pagesize: 10,
        page: 1
      }
    }
  },
  created () {
    this.list()
    // console.log(this.arr)
  },
  methods: {
    // 添加到精选题库
    async add (item) {
    //   await choiceAdd(item)
    //   await remove(item)
      this.list()
    },
    // 修改
    async  amend () {
      await this.$router.push('new')
    },
    // 删除
    async remove (item) {
    //   console.log('remove', id)
      try {
        const res = await this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        })
        if (res === 'confirm') {
          const data = await remove(item)
          if (data.status === 200) {
            this.list()
            return this.$message.success('删除成功')
          }
        }
      } catch (error) {
        console.log(error)
      }
    },
    // 获取基础题库列表
    async list () {
    //   const res = await list()
    //   this.arr = res.data.items
    //   this.total = res.data.counts
    //   console.log(this.total)
      const { data } = await list(this.pageForm)
      //   console.log('22', data)
      this.arr = data.items
      this.total = data.counts
    //   console.log(this.total)
    },
    // 搜索渲染页面
    async newList (value) {
      console.log(value)
      const { data } = await list({ ...this.pageForm, subjectID: value })
      // console.log("32132",res);
      this.arr = data.items
      this.total = data.counts
    },
    getListItem (data) {
      this.getListItemdata = data
    //   console.log(this.getListItemdata)
    },
    // currentPage 改变时会触发--当前页
    handleCurrentChange (val) {
      this.pageForm.page = val
      this.list()
    },
    // pageSize 改变时会触发--每页条数
    async  handleSizeChange (val) {
    //   console.log(val)
      this.pageForm.pagesize = val
      await this.list()
    //   console.log(this.total)
    }
  }

}
</script>

<style scoped lang='less'>
</style>
